package com.summer.safe.base;

import com.summer.safe.config.result.ResultWrapperEntity;
import com.summer.safe.utils.HttpKit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ui.Model;

/**
 * controller基类

 */
public abstract class BaseController {
    /**
     * 日志对象
     */
    protected Logger logger = LoggerFactory.getLogger(getClass());

    protected static String REDIRECT = "redirect:";

    protected String getParameter(String name) {
        return HttpKit.getRequest().getParameter(name);
    }

    /**
     * 添加Model消息
     * @param
     */
    protected void addMessage(Model model, String... messages) {
        StringBuilder sb = new StringBuilder();
        for (String message : messages){
            sb.append(message).append(messages.length>1?"<br/>":"");
        }
        model.addAttribute("message", sb.toString());
    }


    /**
     * 返回成功
     */
    public ResultWrapperEntity success(String msg) {
        return  ResultWrapperEntity.success(msg);
    }

    /**
     * 返回失败消息
     */
    public ResultWrapperEntity error(String msg) {
        return ResultWrapperEntity.error(msg);
    }

}
